
//  Created by 莫瑞权 on 2022/5/6.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit

class TFChatAnnouncementHeaderInSection: UIView, UITextViewDelegate {
    @objc public let close = UIButton()
    @objc public var viewWidth:CGFloat = 0
    @objc public var contentDictheight:CGFloat = 0
    @objc public var dict:TFAnnouncement?
    {
        didSet{
            if (dict != nil)
            {
                self.modelUI(dict!)
                
            }
        }
    }
    func modelUI( _ model:TFAnnouncement)
    {
        self.content.frame = CGRect(x: 10.5, y: 7+21+8, width: self.viewWidth-10.5-10.5, height: self.contentDictheight)
        

     
        let AttributedString =    NSMutableAttributedString.getAttributed(string: dict!.content , font: UIFont.PingFang(size: 14), foregroundColor: UIColor(red: 255/255.0, green: 255/255.0, blue: 255/255.0, alpha: 1))
        self.content.addHyperlink(font: UIFont.PingFang(size: 14), attributedText: AttributedString)
        self.content.attributedText = AttributedString
       
       
    }
    let background = UIView()
    let imageView = UIImageView()
    let title = UILabel()
    let content = TF_StoyCopyTextView()

    override init(frame: CGRect) {
        super.init(frame: frame)

        self.addSubview(self.background)
        
        self.background.backgroundColor = UIColor(red: 49/255.0, green: 52/255.0, blue: 57/255.0, alpha: 1)
        
        self.imageView.image = UIImage.init(named: "HTLive.bundle/announcement1to16")
        self.background.addSubview(self.imageView)
        
        //TODO:公告
        self.title.numberOfLines = 0;
        self.background.addSubview(self.title)
        
        let titleString = NSMutableAttributedString.getAttributed(string: "公告" , font: UIFont.PingFang(size: 15), foregroundColor: UIColor(red: 255/255.0, green: 182/255.0, blue: 55/255.0 , alpha: 1))
      
        self.title.attributedText = titleString;
        self.title.textColor = UIColor(red: 255/255.0, green: 182/255.0, blue: 55/255.0 , alpha: 1)
   
        
        //TODO:关闭窗口
        self.close.backgroundColor = UIColor.clear
        self.close.setImage(UIImage.init(named: "HTLive.bundle/closeWinners"), for: .normal)
        self.background.addSubview(self.close)

        self.content.backgroundColor = UIColor.clear
        self.content.isScrollEnabled = false
        self.content.textContainer.lineFragmentPadding = 0;
        self.content.textContainerInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        self.content.font = UIFont.PingFang(size: 14)
        //禁止输入
        self.content.isEditable = false
        self.background.addSubview(self.content)
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        
        self.background.frame = CGRect(x: 8.5, y: 7.5, width: self.frame.size.width-8.5-8.5, height: self.frame.size.height-7.5)

        self.background.layer.cornerRadius = 10
        
        self.imageView.frame = CGRect(x: 11.5, y: 9.5, width: 16, height: 16)
       
        self.title.frame = CGRect(x: self.imageView.frame.maxX+9.7, y: 7, width: 100, height: 21)
       
        self.close.frame = CGRect(x: self.background.frame.size.width-20-6, y: 7.5, width: 20, height: 20)
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
